package com.code.day17;

import java.util.ArrayList;
import java.util.stream.Stream;

public class Demo01Stream {
    public static void main(String[] args) {
        ArrayList<String> list = new ArrayList<>();
        list.add("古力娜扎");
        list.add("迪丽热巴");
        list.add("马尔扎哈");
        list.add("张三");
        list.add("张无忌");
        list.add("马帅");
        list.add("张杰");
        list.add("鹿晗");
        list.add("吴亦凡");
        list.add("张三丰");
        list.add("张友人");
        System.out.println(list);
//        1.过滤姓张的
        ArrayList<String> zhanglist = new ArrayList<>();
        for (String s : list) {
            if(s.startsWith("张")){
                zhanglist.add(s);
            }
        }
        ArrayList<String> zhangsanlist =new ArrayList<>();
        for (String s : zhanglist) {
            if(s.length()==3){
                zhangsanlist.add(s);
            }
        }
        System.out.println(zhanglist);
        System.out.println(zhangsanlist);

        Stream<String> stream  = list.stream();
        stream.filter(s -> s.startsWith("张")).filter(s -> s.length()==3).forEach(System.out::println);
    }
}
